home *** CD-ROM | disk | FTP | other *** search
- Path: castle.nando.net!news
- From: sekruege@nando.net (Steve Krueger)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: manipulating the stack in C
- Date: 26 Jan 1996 04:02:05 GMT
- Organization: News & Observer Public Access
- Message-ID: <4e9jnt$p5t@castle.nando.net>
- References: <4e8b20$lsq@newshost.lanl.gov>
- NNTP-Posting-Host: vyger410.nando.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-Encoding: 8bit
- X-NewsReader: Interworks_GRn 3.0 January 12, 1996
-
- In article <4e8b20$lsq@newshost.lanl.gov> luke@raj2.tn.cornell.edu (Luke Emmert) writes:
- : I'm currently writing an assembly function that takes a variable
- : number of arguments. The last of the arguments is indicated by forcing
- : the stack to point at itself(a low probability occurence so I hope).
- : The function is called from C code and I therefore need to get C to do
- : something weird with the stack. Unfortunately, I need to make
- : assumptions about how the compiler will produce binary.
- :
- : The code looks like the following:
- :
- : #define LAST_ARG (get_stack())
- :
- : foo( arg1, arg2, arg3, arg4, LAST_ARG );
- :
- : where get_stack() simply returns the current
- : stack value:
- :
- : _get_stack:
- : move.l a7,d0
- : rts
- :
- : The problem arose last night, when I removed a printf() statement
- : that I used for debugging. After disassembling the binary I found that
- : the stack was loaded in different ways in each case. My program
- : assumes a particular way of loading the stack and that's why it failed.
- :
- : What I'd like to do is have something in-line that loads the current
- : stack value rather like
- : move.l a7,(a7)
- : without having to use a function call. I'm currently using SAS C v5.10
- : and I'm pretty sure that this cannot be done, but if any one has a
- : suggestion I would appreciate it.
- :
-
-
- I would recommend that you don't attempt to do this, but if you really
- want to, you might try using the SAS/C function getreg(). For example:
-
- #define LAST_ARG __builtin_getreg(REG_A7)
-
-
- The standard way to accomplish this kind of thing is to have the first
- argument indicate how many arguments will follow.
-
-
- -- |__ o\
- ______ | W \O
- __________ /__ | H\_
- __ ___/_ //_/ | /-\
- _(__ )_ ,< | / \
- /____/ /_/|_| |
- sekruege@nando.net |
-